//
//  LFLocaltionManger.m
//  LocalLife
//
//  Created by 李立达 on 15/11/23.
//  Copyright © 2015年 heima11. All rights reserved.
//

#import "LFLocaltionManger.h"
@interface LFLocaltionManger()<CLLocationManagerDelegate>

@property (strong,nonatomic)CLLocationManager *CLmanger;
@property (assign,nonatomic)sucessLocation sLocal;
@property (assign,nonatomic)errorLocation fLocal;
@property(assign,nonatomic)BOOL local;
@end

@implementation LFLocaltionManger
-(id)init
{
    if(self=[super init])
    {
        _CLmanger=[[CLLocationManager alloc]init];
        
        [_CLmanger requestAlwaysAuthorization];
        
        _CLmanger.delegate=self;
    }
    return self;
}
+(id)shareInstense
{
    static LFLocaltionManger *manger=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        manger=[[LFLocaltionManger alloc]init];
    });
    return manger;
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    [_CLmanger stopUpdatingHeading];
    CLLocation *location=locations.lastObject;
    if(_local)
    {
        self.sLocal(location.coordinate);
        _local=NO;
    }
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    
}
+(void)LocationWithSucess:(sucessLocation)sucess Withfaild:(errorLocation)faild
{
    return [[self shareInstense]LocationWithSucess:sucess Withfaild:faild];
}

-(void)LocationWithSucess:(sucessLocation)sucess Withfaild:(errorLocation)faild
{
    [self.CLmanger startUpdatingLocation];
    
    self.sLocal=sucess;
    _local=YES;
}

@end
